package pruebas;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.ServerSocket;
import java.net.Socket;


import org.json.JSONObject;

import Server.Client;

public class CalculationStub {

	
	public static void main (String[]arg) throws IOException
	{
		System.out.println("calculator");

		ServerSocket welcomeSocket = new ServerSocket(5050);

		
		
		// suscribirse al bus
	    Client c = new Client("127.0.0.1", 4021);        
        JSONObject petition = new JSONObject();
        try {
            petition.put("url", "127.0.0.1");
            petition.put("port", 5050);
            c.sendNoResponseMessage(petition.toString());
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }        
		
		
		// espera mensajes
		while (true)
		{
			// IN
			Socket connectionSocket = welcomeSocket.accept(); 
				
			BufferedReader inFromClient = new BufferedReader(new
				InputStreamReader(connectionSocket.getInputStream())); 
			
			String msg = inFromClient.readLine();
			
			System.out.println(msg);
			connectionSocket.close();
			
			
				
		}		
		

				
		
	}

	
	
}
